#include "MessageBox.h"
#include "MAHeaders.h"
#include "../std.h"
#include "../Utilities/trim.h"
#include "../Widgets/Colours.h"
#include "../Widgets/UIBuilder.h"

MessageBox::MessageBox(){
	mLayout = new Layout(0, 0, APPCONTROLLER->getScreenWidth(), APPCONTROLLER->getScreenHeight(), NULL, 1, 3);
	softKeys = createSoftKeyBar(HEIGHTBAR, getStringNotIterative(L_YES), getStringNotIterative(L_NO));

	Layout* lblBound = new Layout(0,0, APPCONTROLLER->getScreenWidth(), APPCONTROLLER->getScreenHeight()- softKeys->getHeight() - HEIGHTBAR * 3,mLayout, 1, 1);
	lblBound->setDrawBackground(false);

	mTitle = new Label(0, 0, APPCONTROLLER->getScreenWidth(), HEIGHTBAR * 3, mLayout);
	mTitle->setCaption("");
	mTitle->setMultiLine(true);
	mTitle->setHorizontalAlignment(Label::HA_CENTER);
	mTitle->setVerticalAlignment(Label::VA_CENTER);
	mTitle->setBackgroundColor(DARKGOLDENROD);
	//mTitle->setSkin(APPCONTROLLER->getSkin("default"));
	mTitle->setDrawBackground(true);
	mTitle->update(); //Calculate the correct size

	mLayout->add(softKeys);
	this->setMain(mLayout);
}

MessageBox::~MessageBox(){
	delete mLayout;
}

void MessageBox::keyPressEvent(int keyCode, int nativeCode){
	switch(keyCode)
	{
		case MAK_SOFTRIGHT:
		case MAK_SOFTLEFT:
		case MAK_FIRE:
			listener->actionIndex(keyCode);
			break;
	}
}

void MessageBox::pointerReleaseEvent(MAPoint2d point){

}

void MessageBox::pointerPressEvent(MAPoint2d point){
	Point p;
	p.set(point.x, point.y);

	if (softKeys->contains(p)){
		if(softKeys->getChildren()[0]->contains(p)) keyPressEvent(MAK_SOFTLEFT, 0);
		else if (softKeys->getChildren()[1]->contains(p)) keyPressEvent(MAK_SOFTRIGHT, 0);
	}
}

void MessageBox::setListener(MessageBoxListener* input){
	listener = input;
}

void MessageBox::setTitle(String& input){
	mTitle->setCaption(input);
	mTitle->update();
}
